package com.ruoyi.web.controller.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.SysCoursePaper;
import com.ruoyi.course.service.ISysCoursePaperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程试卷Controller
 * 
 * @author YJF
 */
@RestController
@RequestMapping("/coursePaper")
public class SysCoursePaperController extends BaseController
{
    @Autowired
    private ISysCoursePaperService sysCoursePaperService;

    /**
     * 查询课程试卷列表
     */
    @PreAuthorize("@ss.hasPermi('coursePaper:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCoursePaper sysCoursePaper)
    {
        startPage();
        List<SysCoursePaper> list = sysCoursePaperService.selectSysCoursePaperList(sysCoursePaper);
        return getDataTable(list);
    }

    /**
     * 导出课程试卷列表
     */
    @PreAuthorize("@ss.hasPermi('coursePaper:export')")
    @Log(title = "课程试卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCoursePaper sysCoursePaper)
    {
        List<SysCoursePaper> list = sysCoursePaperService.selectSysCoursePaperList(sysCoursePaper);
        ExcelUtil<SysCoursePaper> util = new ExcelUtil<SysCoursePaper>(SysCoursePaper.class);
        util.exportExcel(response, list, "课程试卷数据");
    }

    /**
     * 获取课程试卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('coursePaper:query')")
    @GetMapping(value = "/{coursePaperId}")
    public AjaxResult getInfo(@PathVariable("coursePaperId") Long coursePaperId)
    {
        SysCoursePaper sysCoursePaper = new SysCoursePaper();
        sysCoursePaper.setCoursePaperId(coursePaperId);
        return AjaxResult.success(sysCoursePaperService.selectSysCoursePaperByCoursePaperId(sysCoursePaper));
    }

    /**
     * 新增课程试卷
     */
    @PreAuthorize("@ss.hasPermi('coursePaper:add')")
    @Log(title = "课程试卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCoursePaper sysCoursePaper)
    {
        return toAjax(sysCoursePaperService.insertSysCoursePaper(sysCoursePaper));
    }

    /**
     * 修改课程试卷
     */
    @PreAuthorize("@ss.hasPermi('coursePaper:edit')")
    @Log(title = "课程试卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCoursePaper sysCoursePaper)
    {
        return toAjax(sysCoursePaperService.updateSysCoursePaper(sysCoursePaper));
    }

    /**
     * 删除课程试卷
     */
    @PreAuthorize("@ss.hasPermi('coursePaper:remove')")
    @Log(title = "课程试卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{coursePaperIds}")
    public AjaxResult remove(@PathVariable Long[] coursePaperIds)
    {
        return toAjax(sysCoursePaperService.deleteSysCoursePaperByCoursePaperIds(coursePaperIds));
    }
}
